<?php
/**
 * Created by 无所谓已
 * User: Administrator
 * Date: 2025-08-16
 * Time: 22:00
 */

namespace plugin\csauto\app\service;


use plugin\csauto\app\model\RssModel;
use plugin\csauto\app\model\SiteModel;

class RssWorkService
{
    public static function rssList()
    {
        $rssData = RssModel::where('site_status', 1)->select()->get();
        $siteList = SiteWorkService::siteList(1);
        $rssList = array();
        foreach ($rssData as $item) {
            echo "开始RSS站点 {$item['site_id']} 检查" . PHP_EOL;
            if (!isset($siteList[$item['site_id']])) continue;
            $itemData = $siteList[$item['site_id']];
//            if (!ToolService::CheckRssSite($itemData['site_key'])) continue;
            echo "开始RSS站点 {$item['site_id']} 采集" . PHP_EOL;
            $rssList[] = array(
                'site_id' => $itemData['id'],
                'site_name' => $itemData['site_name'],
                'site_key' => $itemData['site_key'],
                'site_rss' => $item['site_rss'],
                'site_cookie' => $itemData['site_cookie']
            );
        }
        return $rssList;
    }

    public static function requestRssList($rssList)
    {
//        echo ""
        $rssDataList = array();
        foreach ($rssList as $rssItem) {
            if (empty($rssItem['site_rss'])) continue;
            echo "{$rssItem['site_name']}({$rssItem['site_key']}) 开始获取Rss" . PHP_EOL;
            $rssData = ToolService::curlGetData($rssItem['site_rss']);
//            $rssDataList[] = ToolService::getXmlToArr($rssData, $rssItem['site_key'], $rssItem['site_id']);
            /*开始进行检查并操作入库*/
            ToolService::storeTorrent(ToolService::getXmlToArr($rssData, $rssItem['site_key'], $rssItem['site_id']), $rssItem['site_key'], $rssItem['site_cookie']);
        }
        return $rssDataList;
    }


}